package pe.cliente.proyecto.controller.mant;

import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pe.adra.core.bean.ComboBean;
import pe.adra.core.bean.FiltroPaginado;
import pe.adra.core.bean.ValidateResult;
import pe.adra.core.controller.SimpleGenericController;
import pe.adra.util.exception.ControllerException;
import pe.adra.util.exception.ServiceException;
import pe.adra.util.exception.ValidarException;
import pe.cliente.proyecto.core.bean.AsientoBean;
import pe.cliente.proyecto.core.service.mant.AsientoService;

@Controller
@RequestMapping("/controlPanel/asiento")
public class AsientoController extends SimpleGenericController<AsientoBean> {

	private static final Logger log = LoggerFactory.getLogger(AsientoController.class);

	private static String CARPETA = "/asiento";
	private static String JSP = "/asiento";

	@Autowired
	private AsientoService asientoService;

	@RequestMapping(method = RequestMethod.GET)
	public String init(Locale locale, Model model) {
		log.debug("init");
		try {
			List<ComboBean> lstEstadioCBO = asientoService.getListaEstadios();
			model.addAttribute("cboEstadios", lstEstadioCBO);
		} catch (ServiceException e) {
			log.error("error al iniciar", e);
		}
		return RUTA_PRIVADA_MANTENIMIENTO + CARPETA + JSP;
	}

	@Override
	@RequestMapping(value = "/listar", method = RequestMethod.POST, produces = "application/json")
	public @ResponseBody List<AsientoBean> listar(AsientoBean asiento, FiltroPaginado filtro, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, HttpSession httpSession, Model model) throws ControllerException {
		log.debug("listar");
		try {
			filtro.setFiltro(asiento);
			return asientoService.listar(filtro);
		} catch (ServiceException e) {
			log.error("error listar", e);
		}
		return null;
	}

	@Override
	@RequestMapping(value = "/guadar", method = RequestMethod.POST)
	public @ResponseBody void guardar(AsientoBean bean, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, HttpSession httpSession, Model model) throws ControllerException {
		log.debug("guardar");

	}

	@Override
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	public @ResponseBody AsientoBean get(Long id, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, HttpSession httpSession, Model model) throws ControllerException {
		log.debug("get");

		return null;
	}

	@Override
	@RequestMapping(value = "/eliminar", method = RequestMethod.POST)
	public @ResponseBody AsientoBean eliminar(AsientoBean object, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, HttpSession httpSession, Model model) throws ControllerException {
		log.debug("eliminar");

		return null;
	}

	@Override
	public ValidateResult validar(AsientoBean object) throws ValidarException {
		log.debug("validar");

		return null;
	}

}
